<?php

namespace app\admin\controller;

use app\BaseController;
use think\facade\Db; // 数据库的链接

class Index extends BaseController
{
    public function index()
    {
        // 获取平台用户数量
        $user_count = Db::name('user')->count();
        
        // 今日注册用户数量
        $today_user_count = Db::name('user')->whereTime('register_time', 'today')->count();

        // 获取平台店长人数 
        $shop_manager_count = Db::name('user')->where('is_shopowner', 1)->count();

        // 获取平台会长人数
        $shop_count = Db::name('user')->where('is_president', 1)->count();

        // 获取平台金牌总数
        $gold_count = Db::name('user')->sum('gold');

        // 获取平台银牌总数
        $silver_count = Db::name('user')->sum('silver');

        // 获取足球总数
        $football_count = Db::name('ball_user')->where('blevel', 0)->count();
        $football_counts = Db::name('ball_user')->where('blevel', 1)->count();

        // 将上面的数据组装成数组
        
        $data = [
            array(
                'title' => '平台用户',
                'endVal' => $user_count,
                // 'decimals' => 2,
                'prefix' => '',
                'suffix' => '',
                'separator' => ',',
                'duration' => 8000,
                'background' => 'blue',
                'icon' => 'user-line'
            ),
            // 总商家
            array(
                'title' => '今日注册用户',
                'endVal' => $today_user_count,
                'decimals' => 0,
                'prefix' => '',
                'suffix' => '',
                'separator' => ',',
                'duration' => 8000,
                'background' => '',
                'icon' => 'user-line'
            ),
            // 总用户
            array(
                'title' => '平台店长人数',
                'endVal' => $shop_manager_count,
                'decimals' => 0,
                'prefix' => '',
                'suffix' => '',
                'separator' => ',',
                'duration' => 8000,
                'background' => '',
                'icon' => 'user-line'
            ),
            // 总订单   
            array(
                'title' => '平台会长人数',
                'endVal' => $shop_count,
                'decimals' => 0,
                'prefix' => '',
                'suffix' => '',
                'separator' => ',',
                'duration' => 8000,
                'background' => '',
                'icon' => 'user-line'
            ),
            // 今日交额
            array(
                'title' => '平台总金牌',
                'endVal' => $gold_count,
                'decimals' => 2,
                'suffix' => '',
                'separator' => ',',
                'duration' => 8000,
                'background' => '',
                'icon' => 'money-cny-circle-line'
            ),
            // 今日商家
            array(
                'title' => '平台总银牌',
                'endVal' => $silver_count,
                'decimals' => 2,
                'prefix' => '',
                'suffix' => '',
                'separator' => ',',
                'duration' => 8000,
                'background' => '',
                'icon' => 'money-cny-circle-line'
            ),
            // 今日用户
            array(
                'title' => '普通足球',
                'endVal' => $football_count,
                'decimals' => 0,
                'prefix' => '',
                'suffix' => '',
                'separator' => ',',
                'duration' => 8000,
                'background' => '',
                'icon' => 'football-line'
            ),
            // 今日订单
            array(
                'title' => '高级足球',
                'endVal' => $football_counts,
                'decimals' => 0,
                'prefix' => '',
                'suffix' => '',
                'separator' => ',',
                'duration' => 8000,
                'background' => '',
                'icon' => 'football-line'
            ),
        ];
        // 返回数据
        return array('code' => 200, 'msg' => '获取成功', 'data' => $data);
    }
}